import { wxGet, getTownByCode } from '@api'
var wx = require('weixin-js-sdk')
import { mapMutations, mapGetters } from 'vuex'

const someMixins = {
  computed: {
    ...mapGetters(['inWeixin'])
  },
  methods: {
    wxShare(configData) {
      // 分享
      wxGet(encodeURIComponent(configData.link)).then(res => {
        if (res.status == 200) {
          let _res = res.data.data
          wx.config({
            debug: false,
            appId: _res.appId,
            timestamp: _res.timestamp,
            nonceStr: _res.nonceStr,
            signature: _res.signature,
            jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'updateAppMessageShareData', 'updateTimelineShareData']
          })

          wx.ready(() => {
            // 需要传入的值
            // let configData = {
            // 	title: _this.productName,
            // 	link: location.href,
            // 	imgUrl: _this.listThumb && _this.listThumb.split('|')[1] ? _this.listThumb.split('|')[1] : _this.listThumb,
            // 	desc: _this.sellingPoint
            // }

            wx.onMenuShareAppMessage(configData)
            wx.onMenuShareTimeline(configData)
            wx.updateTimelineShareData(configData)
            wx.updateAppMessageShareData(configData)
          })

          wx.error(function (res) {
            console.log('wx_share_wxMixins', res.errMsg)
          })
        }
      })
    }
  }
}

export default someMixins
